<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->resource->path('js') . "/client.js"); ?>
<style type="text/css">
.bid-auto-bid{
	height:345px;
}
.bid-auto-bid .btn.btn-block{
	margin-top:10px;
}
.bid-auto-bid .form-horizontal .control-label{
	width:100%;
}
.form-control-static{
	text-align:left;
}
.bid-auto-bid{
	width:100%;
}
.bid-auto-bid .form-horizontal .control-label{
	text-align:right;
}
.auction-detail .auction-detail-content .auction-detail-description .media-heading{
	color:#f2242e;
    font-weight:bold;
}
.component.component-media .media-content{
    border:solid 1px #6B6C72;	
}
.show-winner-error{
	display:none;
	color:#D40D12;
	margin-bottom:10px;
}
.auction-detail-id{
	position:absolute;
	color:#fff;
	left:38px;
	bottom:18px;
}
.auction-detail-id span{
	color:#fff;
}
.auction-detail .auction-detail-header .auction-title{
	height:42px;
}
.buy-it-now{
	background:url(<?php echo Yii::app()->resource->path('')?>/images/produkt_page_03.jpg);
}
.btn-group-lg>.btn, .btn-lg,.btn-lg:hover ,.btn-lg:focus{
    padding: 7px 16px;
    font-size: 13px;
    line-height: 1.333333;
    border-radius: 6px;
    white-space: normal;
    background-color: #FE6F37;
    border-color: #FE6F37;
    font-weight: bold;
}
.region.region-auction-shelf.shelf-recommend {
    padding-left: 27px;
    padding-right: 36px;
}
.auction-item.auction-item-recommend {
    display: inline-block;
    width: 33%;
    border: none;
    padding: 5px;
    border: solid 1px #ccc;
    margin-left: 3px;
}
.carousel-inner > .item > a > img, .carousel-inner > .item > img{
    width:100%;	
}
.auction-item.auction-item-recommend .auction-title {
    height: 31px;
    max-width: 220px;
}
.auction-detail .auction-detail-content .payment-info{
    float:left;    
}
</style>
<div class="auction-detail">
	<div class="auction-detail-header helper-float-body">
		<h1 class="auction-title helper-float-left">
		<?php
		      $title=$detail->title;
		      if (intval($detail->rookie)){
		          $title.='(Rookie Auction)';
		      }
		      echo $title;
		?>
		</h1>
        
        <div class="auction-detail-id">
				Auction ID:<span class="auction-id"><?php echo  $detail->id ?></span>
		</div>
		<div class="auction-watch-cell helper-float-right">
            <?php //if(!yii::app()->user->isGuest){?>
            <?php
            
            if(Yii::app()->user->isGuest){
                echo "<a href='".Yii::app()->baseUrl."/login/index/url/".strrchr(Yii::app()->request->getUrl(),'a')."'>";
                $this->widget('application.components.widgets.CAddWatchList', array(
                    'auctionId'=> $detail->id
            
                ));
                echo "</a>";
            }else{
                $this->widget('application.components.widgets.CAddWatchList', array(
                    'auctionId'=> $detail->id
                ));
            }
                ?>
            
            <?php //}else{?>
            <!--  <div class="auction-detail-id login">
				Bidder or seller of this item?<br> <a
					href="<?php echo yii::app()->baseUrl?>/login?url=<?php echo strchr(strrchr(Yii::app()->request->getUrl(),"/"),"a")?>">Sign
					in</a> for your status
			</div>
			-->
            <?php //}?>
			<?php if (!Yii::app()->user->isGuest && $detail->status==2 && $payment) {?>
				<a class='btn btn-payment' href='<?php echo Yii::app()->baseUrl."/checkout?id=".$detail->id?>'>
					 Pay
				</a>
			<?php }?>
		</div>

	</div>
	<div class="recommend-auction">
		<div class="region region-auction-shelf shelf-recommend">
			<div class="auction-shelf-content">
                <?php
                        $this->widget('application.components.widgets.CAuctionsPool', array(
                            'id' => 'recommend-auction',
                            'dataProvider' => $model,
                            'itemView' => 'application.components.widgets.auctionPool.item._CAuctionItemRecommend',
        					'emptyText'=>''
                        ))
                ?>
            </div>
			<div class="auction-shelf-footer helper-float-body"></div>
		</div>
	</div>
	<div class="auction-detail-content"
		<?php

if ($detail->status != 2) {
    echo 'auction-id=' . $detail->id;
}
?>
		attribute-data-last_time=0
		attribute-data-end_time=<?php echo $detail->end_time ?>>
		<div class="auction-media-cell">
			<div class="auciton-media">
				<div id="auction-media"
					class="carousel slide component component-media">
					<img src="<?php echo Yii::app()->baseUrl?>/images/increment/increment-cent-1.png" style="position:absolute;margin:5px 0px 0px 5px;z-index:1000;">
					<div class="media-content">
					 <?php 
    					 $specialAuctions=array(3,4,5);
                         $specialAuctionsTitle=array("3"=>'BRONZE',"4"=>'SILVER',"5"=>"GOLD");
                         $specialAuctionsColor=array("3"=>'#89621f',"4"=>'#a9a9a9',"5"=>"#d5b32a");
                         $color="#fff";
                         $title="";
                         if (in_array($detail->type, $specialAuctions)){
                             $color=$specialAuctionsColor[$detail->type];
                             $title=$specialAuctionsTitle[$detail->type];
                         }elseif ($detail->rookie){
                             $color="#ef0000";
                             $title="ROOKIE";
                         }
                        if (in_array($detail->type, $specialAuctions) || $detail->rookie){
                        ?>
                        <div style="z-index:100;position:absolute;border:solid 2px  <?php echo $color?>;right:10px;top:10px;padding:3px;color:<?php echo $color?>;font-size:24px;font-weight:bold;">
                            <?php echo $title?>
                        </div>
                        <?php }?>
                        
                        <?php 
                        if (in_array($detail->type, $specialAuctions) && $detail->rookie){
                        ?>
                        <div style="z-index:100;position:absolute;border:solid 2px  <?php echo "#ef0000"?>;left:10px;bottom:70px;padding:3px;color:<?php echo "#ef0000"?>;font-size:24px;font-weight:bold;">
                            <?php echo "ROOKIE"?>
                        </div>
                        <?php }?>
                        
                        <?php 
                                if($detail->status==2){
                        ?>
                                <div style="position:absolute;z-index:1000;right:20px;top:20px;"><img alt="" src="<?php echo Yii::app()->baseUrl."/images/sold.png"?>"></div>
                        <?php }?>
                    
						<div class="carousel-inner" role="listbox">
                            <?php
                            $images = $detail->images;
                            if (empty($images)) {
                                $images['image_1'] = Yii::app()->resource->path('img') . '/no-image.png';
                            }
                            ?>
                            <?php $imageIndex = 0?>
                            <?php foreach ($images as $image) { ?>
                                <div
								class="item media-item <?php echo ($imageIndex == 0) ? 'active' : null ?>">
								<img src="<?php echo $image ?>"
									onerror="this.src='<?php echo Yii::app()->resource->path('img') . '/no-image.png' ?>'" />
							</div>
                                <?php
                                
                                $imageIndex ++;
                            }
                            ?>
                        </div>
					</div>
					<div class="media-toolbar">
						<ol class="carousel-indicators media-list">
                            <?php $imageIndex = 0?>
                            <?php foreach ($images as $image) { ?>
                                <li class="media-list-item"
								data-target="#auction-media"
								data-slide-to="<?php echo $imageIndex ?>"><img
								class="media-item-thumbnail" src="<?php echo $image ?>" /></li>
                                <?php
                                
                                $imageIndex ++;
                            }
                            ?>
                        </ol>
					</div>
				</div>
			</div>
		</div>

		<div class="auction-info-cell">
			<div class="auction-info">
				<div class="auction-winner-price" attribute="winner_price"
					attribute-animation="flash-value" animation-time=3>
                    <?php
                    $winnerPrice = $detail->winner_price;
                    if (empty($winnerPrice)) {
                        $winnerPrice = '0.00';
                    }
                    echo '$' . $winnerPrice;
                    ?>
                </div>
				<div class="auction-winner" attribute="winner_name">
                     <?php
                    $userName = $detail->user_name;
                    if (empty($userName)) {
                        $userName = 'No bidders yet';
                    }
                    echo $userName;
                    ?>
                </div>
                
                <?php
                $avatar = $detail->avatar;
                if (empty($avatar)) {
                    $avatar = Yii::app()->resource->path('img') . '/no-avatar.png';
                }
                ?>
                
				<!--  <img class="auction-winner-avatar img-circle"
					attribute="winner_avatar" src='<?php echo $avatar ?>' /> -->

                <?php if($detail->status!=2){?>
	                <div class="auction-last-time" attribute="last_date">
					-- : -- : --</div>
                	<div class="show-winner-error"></div>
                	<?php
                    
                    $this->widget('application.components.widgets.CBidAuctionBtn', array(
                        'auctionId' => $detail->id
                    ))?>
                <?php }?>
                <ul class="auction-saving info-list">
					<li class="list-row"><span class="list-lable">Retail Price:</span> <span
						class="list-data" attribute='value_price'>$ <?php echo $detail->value_price ?></span>
					</li>
					<li class="list-row"><span class="list-lable">Current Bid Price:</span> <span
						class="list-data" attribute="winner_price">
								<?php 
									echo '-$ '.$detail->winner_price;
								?>
						</span></li>
					<li class="list-row"  style="display: none;"><span class="list-lable">Bids:</span> <span
						class="list-data" attribute='bids' id='your-cash-bids'>
							<?php 
								if (!Yii::app()->user->isGuest && $detail->status==2) {
									echo '-$ '.$costbids*0.65;
								}else{
									echo '-$ 0.00';
								}
							?>
						</span>
					</li>
					
					<?php if($detail->status==2){?>
					<li class="list-row"  ><span class="list-lable"><?php echo $winnerBids  ?> Bids Placed:</span> <span
						class="list-data" >
							<?php printf("-$%.2f",$winnerBids*0.65)?>
						</span>
					</li>
					<?php }?>
					
					<li class="list-row saving-closing"><span class="list-lable">Your
							savings:</span> <span class="list-data" attribute='savings'
						id='your-savings'> 
								<?php
									if ($detail->status==2) {
										printf("$%.2f",($detail->value_price-$detail->winner_price)-$winnerBids*0.65);
									}elseif ($detail->status==1){
									    printf("$%.2f",($detail->value_price-$detail->winner_price));
									}else{
									    printf("$%.2f",($detail->value_price-$detail->winner_price));
									}
								?>
							</span></li>
					
					<li class="list-row"  ><span class="list-lable">Shipping Cost:</span> <span
						class="list-data" >
							<?php echo "$".$detail->shipping_fee?>
						</span>
					</li>
					
				</ul>
				<div class="helper-small-prompt" style="text-align: left;display:none;">
					The Total Value Price reflects a great<br /> internet price for the
					item(s)<br /> in this Auction.<br />
				</div>
				<?php if(!Yii::app()->user->isGuest && $detail->status!=2){ ?>
				<div class='bid-auto-bid' >
				<div class="panel panel-default">
					<div class="panel-heading">Auto Bid Panel</div>
					<div class="panel-body">
						<form class="form-horizontal" id='autobid-form'>
							<div class="form-group">
								<div class="col-sm-10" style='margin-bottom:5px; '>
							      <p class="form-control-static">You have <?php echo $bids?> bids</p>
							    </div>
							</div>
							
							<div class="form-group">
							     <label style="margin-top:10px;" for="inputBid"
									class="autobid-label col-sm-3">Bids:</label>
								<div class="col-sm-8">
									<input class="form-control" id="inputBid" placeholder="Bids">
							      <?php echo CHtml::hiddenField('autobid_status',1)?>
							    </div>
							</div>
							
							<div class="form-group" style="margin-top:10px;">
							     <label for="inputBid"
									class="autobid-label col-sm-3">Start Price:</label>
							     <label  style="margin-top:8px;width:20px;margin-right:-20px;"  for="inputEmail3" class="col-sm-2">$</label>
								<div class="col-sm-7" style="width:63%;">
									<input class="form-control" id="startPrice" placeholder="">
							    </div>
							</div>
							<div class="form-group">
								<button id='autobid' type="button"
									class="btn btn-success btn-default btn-block">Activate</button>
							</div>
						</form>
					</div>
				</div>
			</div>
			<?php }?>
				<?php if ($detail->status==2 && !Yii::app()->user->isGuest && $payment){?>
				<div class="helper-small-prompt" style="text-align: left;margin-top:10px;margin-bottom:10px;">
					Congratulations You have Won!!!<br /> 
					<a type="button" class="btn btn-primary"  style="margin-top: 10px;background-color:#f2242e;border-color:#f2242e;"
					href="<?php echo Yii::app()->baseUrl.'/myaccount/wonauctions/'.Yii::app()->user->id?>">Get Your Prize</a>
				</div>
				<?php }elseif ($detail->status==2 && !Yii::app()->user->isGuest && !$payment){?>
				
				<div class="helper-small-prompt" style="display:none;text-align: left;margin-top:10px;margin-bottom:10px;">
                    Sorry you have lost but you can redeem your credits for this item<br /> 
                    "Buy it now" Button<br /> 
				</div>
				<?php }?>
			</div>
		</div>
		<div class="bid-history-cell">
			<div class="bid-history">
				<div class="bid-history-header">
					<h2 class="bid-history-title">Bidding History</h2>
					<span class="helper-small-prompt" style="color: #333;">Each bid Raises the Auction by $0.01</span>
				</div>
				<div class="bid-history-content">
					<ul class="bid-history-table">
						<li class="bid-history-table-row row-header"><span
							class="bid-history-table-column">Price</span> <span
							class="bid-history-table-column">Username</span> <span
							class="bid-history-table-column">Type</span></li>
			
						<?php
    if (! empty($bidHistory)) {
        foreach ($bidHistory as $auctionBidLogRow) {
            ?>
						<li class="bid-history-table-row"><span
							class="bid-history-table-column"><?php echo $auctionBidLogRow->winner_price?></span>
							<span class="bid-history-table-column"><?php echo $auctionBidLogRow->winner_name?></span>
							<span class="bid-history-table-column"><?php echo $auctionBidLogRow->action?></span>
						</li>		
                       	<?php
        }
    }
    ?>  
                    </ul>
				</div>
				<div class="bid-history-footer"></div>
				<button type="button" class="btn btn-primary btn-lg btn-block btn-bin-purchase hidden">
				You can now use your BIN Credits
				to purchase this item
				</button>
			</div>
            <?php if(!yii::app()->user->isGuest && $detail->status != 2){?>
            <div class='bid-auto-bid'  style="display: none;">
				<div class="panel panel-default">
					<div class="panel-heading">Auto Bid Panel</div>
					<div class="panel-body">
						<form class="form-horizontal" id='autobid-form'>
							<div class="form-group">
								<div class="col-sm-10" style='margin-bottom:5px; '>
							      <p class="form-control-static">You have <?php echo $bids?> bids</p>
							    </div>
							</div>
							<div class="form-group">
								<label for="inputBid"
									class="autobid-label col-sm-2 control-label">Bids</label>
								<div class="col-sm-8">
									<input class="form-control" id="inputBid" placeholder="Bids">
							      <?php echo CHtml::hiddenField('autobid_status',1)?>
							    </div>
							</div>
							<div class="form-group">
								<label class="autobid-label col-sm-2 control-label"></label>
								<div class="col-sm-8">
									<p class="autobid-tips form-control-static"></p>
								</div>
							</div>
							<div class="form-group">
								<button id='autobid' type="button"
									class="btn btn-success btn-default btn-block">Auto Bid On</button>
							</div>
						</form>
					</div>
				</div>
			</div>
            <?php }?>
        </div>

      <!-- 未登录不显示 -->
      <?php 	if (!Yii::app()->user->isGuest) { ?>
		<div class='buy-it-now'>
			<div class='col-sm-2'>
				<h1>Buy it now</h1>
			</div>
			<div class='col-sm-3 purchase-saving'>
				<table class='table'>
					<tr>
						<td class='left'>Retail Price:</td>
						<td>$ <?php echo $detail->value_price ?></td>
					</tr>
					<tr>
						<td class='left'>Cash Bids Applied:</td>
						<td id="bin-panel-cashapplied">
						          <?php ($costbids>0)?printf("-$%.2f",$costbids*0.5):printf("$ %.2f",0); ?>
						</td>
					</tr>
					<tr class='your-saving'>
						<th>Your Purchase Price:</th>
						<td  id="bin-panel-saving">$ <?php 
									if (!Yii::app()->user->isGuest) {
										//echo (round($detail->value_price-$costbids*0.5,2));
										printf("%.2f",$detail->value_price-$costbids*0.5);
									}else{
										//echo round($detail->value_price,2);
										printf("%.2f",$detail->value_price);
									}
							 ?></td>
					</tr>
				</table>
			</div>
			<div class='col-sm-2 buy-it-now-option'>
				<a class='more-info-bin'>Need more information <br>about "Buy it Now"
					option?</a>
			    <?php if(true){?>      
				<?php
				    $this->widget('application.components.widgets.BuyitnowButton', array(
				        // 'url'=>Yii::app()->baseUrl.'/checkout/index?id='.$detail->id.'&orderType=2',
				        'auction_id' => $detail->id,
				    ));
				?>
				<?php }?>
		</div>
			<div class='col-sm-2 add-wathc-list-option'  style="display: none;">
				<div class='content'>Don't want to buy it now?</div>
			<?php
				if(Yii::app()->user->isGuest){
					echo "<a href='".Yii::app()->baseUrl."/login/index/url/".strrchr(Yii::app()->request->getUrl(),'a')."'>";
					$this->widget('application.components.widgets.CAddWatchList', array(
				    'auctionId'=> $detail->id
				    
					));
					echo "</a>";
				}
				else{
					$this->widget('application.components.widgets.CAddWatchList', array(
				    'auctionId'=> $detail->id
					));
				}
				
			?>
		</div>
		</div>
        <?php }?>


		<div class="auction-detail-description">
			<div class="media">
				<div class="media-left">
					<h4 class="media-heading">Description</h4>
				</div>
				<div class="media-body auction-description">
                    <?php echo $detail->description?>
                </div>
			</div>
		</div>
		<div class="rght_seps boxs_size clearfix">
		<h3 class="prel_lite">Partners</h3>
			<ul>
				<li>
					<a href="https://www.youtube.com/user/hickok45" target="_blank"><img src="<?php echo Yii::app()->params['admin_url'].'/images/logo-ad/hickok-banner.png'?>" width="200"></a>
				</li>
				<li>
					<a href="https://www.propertyroom.com?&utm_source=EGUNNER&utm_medium=PARTNERS" target="_blank"><img src="<?php echo Yii::app()->params['admin_url'].'/images/logo-ad/200xNxpartner-images4.jpg'?>" width="200"></a>
				</li>
				<li>
					<a href="http://www.shipmygun.com" target="_blank"><img src="<?php echo Yii::app()->params['admin_url'].'/images/logo-ad/200xNxnew_budsgunshop_com_logo.png'?>" width="200"></a>
				</li>
				<li>
					<a href="http://www.nssf.org/" target="_blank"><img src="<?php echo Yii::app()->params['admin_url'].'/images/logo-ad/xpartner-images1.png'?>"></a>
				</li>
				<li>
					<a href="http://bluebookofgunvalues.com/?utm_source=egunner&utm_medium=banner&utm_campaign=homepage" target="_blank"><img src="<?php echo Yii::app()->params['admin_url'].'/images/logo-ad/x100x175KnowWorth.jpg'?>"></a>
				</li>
				<li>
					<img src="<?php echo Yii::app()->params['admin_url'].'/images/logo-ad/xmcafee.png'?>">
					<img src="<?php echo Yii::app()->params['admin_url'].'/images/logo-ad/xentrust.png'?>">
				</li>
				<li>
					<a href="http://www.budsgunshop.com/?utm_source=egunner&utm_medium=banner&utm_campaign=homepage" target="_blank"><img src="<?php echo Yii::app()->params['admin_url'].'/images/logo-ad/200xNxsmg.png'?>" width="200"></a>
				</li>

			</ul>
		</div>
	</div>
	<div class="clear"></div>
	<!--<div class="auction-detail-footer"></div>-->
</div>
<style>
.btn.btn-payment{
	background-color:#f2242e;
	color:#fff;
	position:absolute;
	right:58px;
	margin-top:10px;
	bottome:5px;
	font-weight:700;	
	top:63px;
}
.region.region-auction-shelf.shelf-recommend .auction-pool-pager {
	visibility: hidden;
	height: 20px;
}

.region.region-auction-shelf.shelf-recommend .prev, .region.region-auction-shelf.shelf-recommend .next
	{
	visibility: visible;
	z-index: 100;
	position: absolute;
	top: 75px;
}

.region.region-auction-shelf.shelf-recommend .prev {
	left: 5px;
}

.region.region-auction-shelf.shelf-recommend .next {
	right: 5px;
}

.region.region-auction-shelf.shelf-recommend {
	position: relative;
}

.region.region-auction-shelf.shelf-recommend .auction-pool-item {
	padding-left: 8px;
}
.bidhistory-odd{
	background-color:rgb(255, 255, 102);
}
</style>
<script type="text/javascript">
		<?php if(yii::app()->user->id){?>
    		$('#autobid').on('click',function(){
                $('#autobid-form').submit(); 
            });

			function activateAutobid(){
				var amount=$('#inputBid').val();
				var startPrice=$('#startPrice').val();
				$.ajax({
                    url:'<?php echo Yii::app()->baseUrl."/ajax/activateautobid"?>',
                    data:{
                        		'customer_id':<?php echo Yii::app()->user->id?>,
                            	'auction_id':<?php echo $detail->id?>,
                                'end_time':<?php echo $detail->end_time?>,
                                'amount':amount,
                                'start_price':startPrice
                            },
                    type:'post',
                    dataType:'json',
                    success:function(data){
                    	$('#inputBid').val("");
                    	$('#startPrice').val("");
                        alert(data.result);
                    }
                });    
			}
			
            $('#autobid-form').on('submit',function(){
           	    activateAutobid();
                return false;
            })	
        <?php }?>

                           
	   	function auctionSaving(){
			this.value_price=<?php echo $detail->value_price?>;
			this.winner_price=0;
			this.bids=0;
			this.saving;
			this.setBids=function(bds){
				var bidValue=bds*0.65
				bidValue=parseFloat(bidValue);
				bidValue=bidValue.toFixed(2);
				this.bids=bidValue;
				return this;
			}

			this.setWinnerprice=function(wprice){
				this.winner_price=wprice;
				return this;
			}
			
			this.calculateSavings=function(){
				var svs=this.value_price-this.bids-this.winner_price;
				svs=parseFloat(svs);
				svs=svs.toFixed(2);
				this.saving=svs;
			}
			this.setDomValue=function(){
				this.calculateSavings();
				$('#your-savings').html(this.saving);
				$('#your-cash-bids').html(this.bids);	
			}
	   	} 
	
	   	saving = (function (obj) {
	   	    "use strict";
	   	    var _obj = false;
	   	    if (_obj === false) {
	   	        _obj = new obj();
	   	    }
	   	    return _obj;
	   	})(auctionSaving);

	    function bidHistoryDom($data){
			var bidDomHeader ='<li class="bid-history-table-row row-header"><span class="bid-history-table-column">Price</span><span class="bid-history-table-column">Username</span><span class="bid-history-table-column">Type</span></li>';
			var htmlDom=bidDomHeader;
			var flash = 'flash-value';
			for(var i in $data){
				var price=$data[i]['price'];
				var winner=$data[i]['winner'];
				var bidder_type=$data[i]['bidder_type'];
				var oddClass=' ';
				if(i%2){
					oddClass=' bidhistory-odd ';	
				}
				var bidDomContent='<li class="bid-history-table-row '+oddClass+flash+'">'+
										'<span class="bid-history-table-column">'+price+'</span>'+
								        '<span class="bid-history-table-column">'+winner+'</span>'+
								        '<span class="bid-history-table-column">'+bidder_type+'</span>'+
		        				  '</li>';
				htmlDom+=bidDomContent;		
				flash = '';			
			}
	    	return htmlDom;
	    }
	    
	    $(function () {
			$('.btn-bin-purchase').on('click',function(){
    			$('.auction-buy-it-now').trigger('click');
			})
		    
	        $auctionDetail = $('.auction-detail-content').auctionDetail({}).initDomData().auctionDom();
	        $auctionDetail.setBaseEvent('winner_price.dom.setFormat',function(value){
                return '$'+value;
            })
	        
	        $auctionDetail.setBaseEvent('winner_avatar.dom.setAttributeBefore',function(value, attribute, attributeDom, auctionDom){
                attributeDom.on('error',function(){
		          $(this).attr('src','<?php echo Yii::app()->resource->path('img').'/no-avatar.png'?>');
		        });
                return true;
            });

			client.setHash('detailID',<?php echo $detail->id?>);
	        
	        client.engine.selectTimer('engineAuctionInfo').
	        	addRequestData('type',['detail',{'auctionId':<?php echo $detail->id?>}]).
	        	setResponseEvent('bidHistory', function (response) {
					if(response.hasOwnProperty('rData')){
						var winnerError=client.getHash('winner_error');
						console.log(winnerError);
						if(winnerError!==undefined){
							$(".show-winner-error").show().html(winnerError);
						}else{
							$(".show-winner-error").hide().html("");
						}
						var detailId=<?php echo $detail->id?>;
						var overcostList=client.getHash('overcost');
						if(overcostList===undefined){overcostList=[]};
						for(var overItem=0;overItem<overcostList.length;overItem++){
							if(overcostList[overItem]==detailId){
								$('.btn-bin-purchase').removeClass('hidden');
								break;
							}
						}
						for(var rDataAuctionId in response.rData){
							if(response.rData[rDataAuctionId].hasOwnProperty('type') && response.rData[rDataAuctionId].type == 'detail'){
								if(response.rData[rDataAuctionId].status == 2){
									window.location.reload();
								}
							}
							if(response.rData[rDataAuctionId].hasOwnProperty('rBidHistory')){
								var html=bidHistoryDom(response.rData[rDataAuctionId].rBidHistory);								
								$('.bid-history-table').html(html);
							}
							if(response.rData[rDataAuctionId].hasOwnProperty('customerBidAuctionInfo')){
								/*
									获取用户对此auction所花bid数目
								*/
								var customerBidAuctionInfo = response.rData[rDataAuctionId].customerBidAuctionInfo;
								var costBid = 0;
								if(customerBidAuctionInfo.hasOwnProperty('cash')){
									costBid += parseInt(customerBidAuctionInfo.cash);
								}
								var retailPrice=<?php echo $detail->value_price ?>;
								var cashApplied=parseFloat(costBid*0.5).toFixed(2);
								var cashSaving=parseFloat(retailPrice-cashApplied).toFixed(2);
								$("#bin-panel-saving").html("$"+cashSaving);
								$("#bin-panel-cashapplied").html("$"+cashApplied);
							}
						}						
					}
		        });
   		 });
</script>